package com.corn.prometheus.binder;

import com.corn.prometheus.service.StatiscService;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2022/6/13 11:46
 */

@Component
public class MyMeterBinder implements MeterBinder {
    @Autowired
    private StatiscService statiscService;

    @Value("${spring.application.name}")
    private String applicationName;

    @Override
    public void bindTo(MeterRegistry meterRegistry) {
        // Meter的名称
        Gauge.builder("MyGauge", () -> statiscService.statisticsTest())
                // Meter单位 会以 MeterName_Unit进行拼接
                .baseUnit("ge")
                // Meter的注释
                .description("测试我的prometheus gauge")
                .strongReference(true)
                .tag("application", applicationName)
                .register(meterRegistry);
    }
}
